package com.zhonghan.recharge.controller;

import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhonghan.common.utils.ExcelUtils;
import com.zhonghan.common.utils.StringUtils;
import com.zhonghan.recharge.pojo.ZhFillCard;
import com.zhonghan.recharge.service.ZhFillCardService;

@Controller
public class TestExcel {

	@Autowired
	private ZhFillCardService zfcc;
	
	
	@RequestMapping("/export")
	public void test(){
		
		List<ZhFillCard> zfcList = new ArrayList<>();
		
		Class<ZhFillCard> clazz = ZhFillCard.class;
		File file = new File("E:/card_info/1000.xls");
		int price = 1000;
		
		String[] beanPropertys = {"sequence","password"};
		List<ZhFillCard> list = ExcelUtils.excelParserList(clazz, file, beanPropertys,0);
		for (ZhFillCard z : list) {
			//z.getSequence();
			String password = z.getPassword();
			
			System.out.println("sequence: " + z.getSequence());
			System.out.println("password: " + z.getPassword());
			
			z.getOverdueTime();
			z.getConsumeTime();
			z.getOutPrice();
			z.getReceiveTelephone();
			z.getCreaterTime();
			z.getStatus();
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			z.setPassword(password);
			System.out.println("加密后的密码是: " + z.getPassword());
			z.setFacePrice(price);//设置面额
			System.out.println("面额: " + price);
			
			z.setOverdueTime("2020-12-31");//设置过期时间
			z.setConsumeTime("");//设置消费时间为空
			z.setOutPrice(null);//设置售价
			z.setReceiveTelephone(null);
			z.setCreaterTime(sdf.format(new Date()));
			z.setStatus(-1);
			
			zfcList.add(z);
		}
		System.out.println(price + "元	准备开始导入数据");
		int result = zfcc.insertZhFillCardByBatch(zfcList);
		System.out.println(price + "元	导入成功" + result);
	}
	
	
}
